//import Cookies from 'js-cookie'
import qs from "qs";

const TokenKey = 'Oauth2-Token'

export function getToken() {
    const json = localStorage.getItem(TokenKey);
    return qs.parse(json);
}

export function setToken(token) {
    return localStorage.setItem(TokenKey, qs.stringify(token));
}

export function removeToken() {
    return localStorage.removeItem(TokenKey);
}

export function getAccessToken() {
    const obj = getToken();
    const tokenType = obj.token_type;
    return tokenType + " " + obj.access_token;
}

export function getRefreshToken() {
    let obj = getToken();
    return obj.refresh_token;
}

/*
  {
      "access_token": "968f2804-f1f1-4ca0-a8a1-97ea1c1d3622",
      "token_type": "bearer",
      "refresh_token": "d0a10ebb-1517-4844-b962-59dc4658e925",
      "expires_in": 7199,
      "scope": "select"
  }
*/